package com.chaoxin.lovehelp.aop;

import com.chaoxin.lovehelp.entity.FellowEntity;
import com.chaoxin.lovehelp.common.enums.SystemEnum;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author TengJay Huang
 * @version 1.0
 */
// 新建 LoginInterceptor 类
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        FellowEntity user = (FellowEntity) request.getSession().getAttribute(SystemEnum.LOGIN_STATUS.getName());
        if (user == null) {
            throw  new UnauthorizedException("请先登录"); // 抛出自定义异常
        }
        return true;
    }
}
